<template>
	<el-main class="bg edit_wrap comtable_e">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
      <el-row class="row_ce">
        <el-col v-if="$check_field('get','region_name') || $check_field('add','region_name') || $check_field('set','region_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
          <el-form-item label="地区名称" prop="region_name">
            <el-input id="region_name" v-model="form['region_name']" placeholder="请输入地区名称"
                      v-if="(form['region_name_id'] && $check_field('set','region_name')) || (!form['region_name_id'] && $check_field('add','region_name'))" :disabled="disabledObj['region_name_isDisabled']"></el-input>
            <div v-else-if="$check_field('get','region_name')">{{form['region_name']}}</div>
          </el-form-item>
        </el-col>
        <el-col v-if="$check_field('get','street_name') || $check_field('add','street_name') || $check_field('set','street_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
          <el-form-item label="街道名称" prop="region_name">
            <el-input id="street_name" v-model="form['street_name']" placeholder="请输入街道名称"
                      v-if="(form['region_name_id'] && $check_field('set','street_name')) || (!form['region_name_id'] && $check_field('add','street_name'))" :disabled="disabledObj['region_name_isDisabled']"></el-input>
            <div v-else-if="$check_field('get','street_name')">{{form['region_name']}}</div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
        <el-form-item v-if="$check_action('/region_name/view','set') || $check_action('/region_name/view','add') || $check_option('/region_name/table','examine')">
          <el-button type="primary" @click="submit()">提交</el-button>
          <el-button @click="cancel()">取消</el-button>
        </el-form-item>
        <el-form-item v-else>
          <el-button @click="cancel()">返回</el-button>
        </el-form-item>
      </el-col>
		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";
	export default {
		mixins: [mixin],
		data() {
			return {
				field: "region_name_id",
				url_add: "~/api/region_name/add?",
				url_set: "~/api/region_name/set?",
				url_get_obj: "~/api/region_name/get_obj?",
				url_upload: "~/api/region_name/upload?",

				query: {
					"region_name_id": 0,
				},

				form: {
          "region_name":  '', // 地区名称
          "street_name":'',
          "region_name_id": 0, // ID
        },
				disabledObj:{
          "region_name_isDisabled": false,
        },
			}
		},
		methods: {
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";

				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
								this.form[key] = form[dbKey]
							}
							if(dbKey === "source_table"){
								this.form['source_table'] = form[dbKey];
							}
							if(dbKey === "source_id"){
								this.form['source_id'] = form[dbKey];
							}
							if(dbKey === "source_user_id"){
								this.form['source_user_id'] = form[dbKey];
							}
						})
					})
				}
						$.db.del("form");

				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){


			},

																			async submit(param, func){
				if (!param) {
					param = this.form;
				}

				var pm = this.events("submit_before", Object.assign({}, param)) || param;
				var msg = await this.events("submit_check", pm);
				var ret;
				if (msg) {
					this.$toast(msg, 'danger');
				} else {
															ret = this.events("submit_main", pm, func);
				}
				return ret;
			},

			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
						submit_check(param) {

																	return null;
			},

			is_view(){
				// var bl = this.user_group == "管理员";
				var bl = false;

				if(!bl){
					bl = this.$check_action('/region_name/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/region_name/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/region_name/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/region_name/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/region_name/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
				},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}

	.img_multiple{
		overflow: hidden;
	}
	.img_multiple .img_block{
		float: left;
		margin-right: 5px;
		margin-bottom: 5px;
		position: relative;
	}
	.img_multiple .img_block img{
		height: 100px;
		width: auto;
	}
	.img_multiple .img_del{
		position: absolute;
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
		background: #0000008a;
		color: #fff;
		line-height: 20px;
		text-align: center;
		border-radius: 100%;
		cursor: pointer;
	}





</style>
